import os
import random
import shutil

# 指定包含图片的文件夹路径
img_path = "../images"

# 指定支持的图片文件的扩展名
support_suf = ['.jpg', '.jpeg', '.png', '.gif', '.bmp']

# 获取文件夹中所有的图片文件的路径
img_files_path = []
for root, dirs, files in os.walk(img_path):
    for f in files:
        if os.path.splitext(f)[1].lower() in support_suf:
            img_files_path.append(os.path.join(root, f))

print(img_files_path)
print(len(img_files_path))
#随机选择20张图片
num_chose_path = min(20,len(img_files_path))
random_choose_img = random.sample(img_files_path,num_chose_path)
# 3. 打印路径
print(random_choose_img)
print(len(random_choose_img))
#4复制
new_path ="../new_images"
if os.path.exists(new_path):
    print("已存在，不要创建了")
else:
    os.mkdir(new_path)
    for f in random_choose_img:
        shutil.copy(f,new_path)



